package com.tanovo.api;

import com.tanovo.bo.EsBatchAddReq;
import com.tanovo.bo.ResultObject;
import com.tanovo.service.EsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("es")
@Api(tags = "es搜索服务")
public class EsServiceApi {
    @Autowired
    private EsService esService;

    @PostMapping("upsetIndex")
    @ApiOperation(value = "添加索引")
    public ResultObject upsetIndex(@RequestBody EsBatchAddReq requestParam) {
        esService.upsetIndex(requestParam);
        return null;
    }

    @PostMapping("createIndex")
    @ApiOperation(value = "创建索引对象")
    public ResultObject<CreateIndexResponse> createIndex(@RequestParam String indexName) {
        CreateIndexResponse index = esService.createIndex(indexName);
        return new ResultObject<>(index);
    }
}
